package com.dongdongsongcan.app.fragment;

import android.view.View;
import android.widget.EditText;

import com.dongdongsongcan.app.R;
import com.dongdongsongcan.app.activity.MainActivity;
import com.dongdongsongcan.app.control.UserControl;
import com.dongdongsongcan.app.control.bean.UserData;
import com.su.dolphin.control.task.CtrlTask.IControlResponse;
import com.su.dolphin.utils.ui.TipsUtil;
import com.su.dolphin.view.fragment.BaseFragment;

public class LoginAccountFragment extends BaseFragment {

    private EditText mLogin_account_et_name;
    private EditText mLogin_account_et_pwd;

    private View mLogin_account_forgetpwd;
    private View mLogin_account_btn_login;

    @Override
    public void initView() {
        mLogin_account_et_name = (EditText) getView().findViewById(
                R.id.login_account_et_name);
        mLogin_account_et_pwd = (EditText) getView().findViewById(
                R.id.login_account_et_pwd);

        mLogin_account_btn_login = getView().findViewById(
                R.id.login_account_btn_login);
        mLogin_account_forgetpwd = getView().findViewById(
                R.id.login_account_forgetpwd);

    }

    @Override
    public void setListener() {
        mLogin_account_btn_login.setOnClickListener(this);
        mLogin_account_forgetpwd.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.login_account_btn_login:
                String user_name = mLogin_account_et_name.getText().toString()
                        .trim();
                String user_pwd = mLogin_account_et_pwd.getText().toString().trim();
                UserControl.i().user_login(user_name, user_pwd,
                        new IControlResponse<UserData>() {

                            @Override
                            public void onControlResponse(UserData data) {
                                if (data.getError() == 0) {
                                    UserControl.i().saveUser(data.getResult());
                                    getActivity().finish();
                                }
                                TipsUtil.toast(data.getMsg());
                            }
                        });
                break;
            case R.id.login_account_forgetpwd:

                break;
            default:
                break;
        }
    }

    @Override
    public void initData() {

    }

    @Override
    protected int onSetContentView() {
        return R.layout.fragment_login_account;
    }

}
